import { createApp } from "vue";
import App from "./App";
import router from "./router";
import store from "./store";

import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import './style/index.scss'



import props from './interface/props'
import globalData from './interface/globalData'

let app: any;
if (window.__POWERED_BY_QIANKUN__) {
  window.__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}

async function render(container?: String) {

  app = createApp(App);
  app.use(Antd);
  app.use(store);
  app.use(router);
  app.mount(container ? container : "#app");
}

if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function mount(props: props) {
  store.commit("props", props);
  props.onGlobalStateChange((value: globalData) => {
    if (value.userInfo) {
      store.commit("userInfo", value.userInfo);
    }
    if (value.mapConfig) {
      store.commit("MAP_INIT_CONFIG", value.mapConfig);
    }
  }, true);
  render('#micro_app #app')
}

export async function unmount() {
  if (app) {
    app.unmount();
  }
  app = {};
}

export async function update() {
  console.log("update props");
}

export async function bootstrap() {
  console.log("bootstrap");
}